﻿using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;

using BLL;
using Model;
using Utility;

namespace EvaluationSystem.Enterprise
{
    public partial class ContactModify : System.Web.UI.Page
    {
        private string m_UserName = string.Empty;
        private string m_UserCompany = string.Empty;
        private EnterpriseUserBLL m_EnterpriseUserBll = new EnterpriseUserBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            ((SiteEnterpriseMaster)Master).InitMenu();
            ((SiteEnterpriseMaster)Master).li2.Attributes.Add("class", "hover ccc");
            ((SiteEnterpriseMaster)Master).b_hmenu1.Style.Add("display", "none");
            ((SiteEnterpriseMaster)Master).b_hmenu2.Style.Clear();
            ((SiteEnterpriseMaster)Master).b_hmenu3.Style.Add("display", "none");
            ((SiteEnterpriseMaster)Master).b_hmenu4.Style.Add("display", "none");
            ((SiteEnterpriseMaster)Master).s_menu2_3.Style.Add("COLOR", "#147ab8");
            ((SiteEnterpriseMaster)Master).s_menu2_3.Style.Add("TEXT-DECORATION", "none"); 

            /*判断是否是企业用户身份*/    
            if (Session["username"] == null)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "PopupScript", "<script>alert('请先登录系统!');top.location.href='../Enterprise/EnterpriseLogin.aspx';</script>");
                return;
            }
            else
            {
                if (!IsPostBack)
                {
                    m_UserName = Session["username"].ToString();
                    m_UserCompany = m_EnterpriseUserBll.GetIncNameByUser(m_UserName);
                    string userId = m_EnterpriseUserBll.GetEnterpriseIdByUser(m_UserName);
                    EnterpriseUser temp = m_EnterpriseUserBll.GetModel(int.Parse(userId));
                    lblUserName.Text = m_UserName;
                    lblCoName.Text = m_UserCompany;
                    // txtbAddress.Text = temp.Users_address;
                    txtbContact.Text = temp.Users_contact;
                    txtbPhone.Text = temp.Users_phone;
                    ddlCoScale.Text = temp.Users_scale;
                    ddlCoType.Text = temp.Users_type;
                }
            }
        }

        protected void btnChange_Click(object sender, EventArgs e)
        {
            EnterpriseUser temp = new EnterpriseUser();

            temp.Username = lblUserName.Text.Trim();
            temp.Users_incname = lblCoName.Text.Trim();
           // temp.Users_address = txtbAddress.Text.Trim();
            temp.Users_contact = txtbContact.Text.Trim();
            temp.Users_phone = txtbPhone.Text.Trim();
            temp.Users_scale = ddlCoScale.SelectedValue;
            temp.Users_type = ddlCoType.SelectedValue;

            if (m_EnterpriseUserBll.UpdateContact(temp) > 0)
            {
                MessageBox.ShowAndRedirect(this, "修改成功", "ManageActivity.aspx");
            }
        }
    }
}